﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PTUDW_CNTN2010_F_CDT.Models;

namespace PTUDW_CNTN2010_F_CDT.Controllers
{
    public class ShoppingCartController : Controller
    {
        EcommerceDBContext db = new EcommerceDBContext();
        
        [ChildActionOnly]
        public ActionResult GetSumaryCart()
        {
            var shoppingCart = ShoppingCart.GetCart(this.HttpContext);

            ViewBag.SumCart = shoppingCart.GetCount();
            return PartialView();
        }

        public ActionResult AddToCart(int id)
        {
            var product = db.Products
                .Single(p => p.ProductId == id);
            var cart = ShoppingCart.GetCart(this.HttpContext);

            cart.AddProductToCart(product);

            return RedirectToAction("Index", "Home");
        }
    }
}
